home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Graphics & Imaging / Ultra Dragging 1.0ß1 / UReliefGridView.p < prev   
Encoding:
Text File  |  1991-05-10  |  13.9 KB  |  515 lines  |  [TEXT/MPS ]

  1. { UReliefGridView.p }
  2. { Copyright © 1984-1990  Apple Computer, Inc.  All rights reserved. }
  3.  
  4. UNIT UReliefGridView;
  5.  
  6. INTERFACE
  7.  
  8.     USES
  9. {$IFC UNDEFINED THINK_PASCAL}
  10.     { • MacApp }
  11.         UMacApp, Resources,
  12.  
  13. {$ELSEC }
  14.         SysEqu, Traps, ULoMem, UMacAppUtilities, UPatch, UObject, UViewCoords, UMemory, UFailure, UMenuSetup, UList, PrintTraps, UAssociation, UMacApp, 
  15. {$ENDC}
  16.  
  17.         UGridView;
  18.         
  19.         
  20.     CONST
  21.  
  22.         kBkgndColorRsrcType = 'BKCL';
  23.         kSideColorRsrcType = 'SDCL';
  24.  
  25.     TYPE
  26.  
  27.         BkgndColor = RECORD            { BKCL resources -- these resources determine the color of the    }
  28.                 redPart: INTEGER;            { background of TBkgndGridViews.                                        }
  29.                 greenPart: INTEGER;
  30.                 bluePart: INTEGER;
  31.             END;
  32.         BkgndColorPtr = ^BkgndColor;
  33.         BkgndColorHdl = ^BkgndColorPtr;
  34.  
  35.         SideColors = RECORD            { SDCR resources -- these resources determine the color of the    }
  36.                 redPartLightestSide: INTEGER;
  37.                 greenPartLightestSide: INTEGER;
  38.                 bluePartLightestSide: INTEGER;
  39.                 redPartLightSide: INTEGER;
  40.                 greenPartLightSide: INTEGER;
  41.                 bluePartLightSide: INTEGER;
  42.                 redPartDarkSide: INTEGER;
  43.                 greenPartDarkSide: INTEGER;
  44.                 bluePartDarkSide: INTEGER;
  45.                 redPartDarkestSide: INTEGER;
  46.                 greenPartDarkestSide: INTEGER;
  47.                 bluePartDarkestSide: INTEGER;
  48.             END;
  49.         SideColorsPtr = ^SideColors;
  50.         SideColorsHdl = ^SideColorsPtr;
  51.  
  52.         TBkgndGridView = OBJECT(TGridView)
  53.                 fBkgndColor: RGBColor;
  54.  
  55.                 PROCEDURE TBkgndGridView.IRes (itsDocument: TDocument; itsSuperview: TView; VAR itsParams: Ptr);
  56.                 OVERRIDE;
  57.                 PROCEDURE TBkgndGridView.Fields (PROCEDURE DoToField (fieldName: Str255; fieldAddr: Ptr; fieldType: INTEGER));
  58.                 OVERRIDE;
  59.                 PROCEDURE TBkgndGridView.DrawCell (aCell: GridCell; aQDRect: Rect);
  60.                 OVERRIDE;
  61.                 PROCEDURE TBkgndGridView.DrawBkgnd (aCell: GridCell; aQDRect: Rect);
  62.                 PROCEDURE TBkgndGridView.AdornFirstRowsTop (area: Rect);
  63.                 PROCEDURE TBkgndGridView.AdornRow (aRow: INTEGER; area: Rect);
  64.                 OVERRIDE;
  65.                 PROCEDURE TBkgndGridView.AdornFirstColsLeft (area: Rect);
  66.                 PROCEDURE TBkgndGridView.AdornCol (aCol: INTEGER; area: Rect);
  67.                 OVERRIDE;
  68.                 PROCEDURE TBkgndGridView.SetColor (newColor: RGBColor);
  69.                 FUNCTION TBkgndGridView.GetColor: RGBColor;
  70.  
  71.                 PROCEDURE TBkgndGridView.GetBkgndColor;
  72.             END;
  73.  
  74.         TReliefGridView = OBJECT(TBkgndGridView)
  75.                 fLightestSideColor: RGBColor;
  76.                 fLightSideColor: RGBColor;
  77.                 fDarkSideColor: RGBColor;
  78.                 fDarkestSideColor: RGBColor;
  79.                 fSideWidth: Integer;
  80.  
  81.                 PROCEDURE TReliefGridView.IRes (itsDocument: TDocument; itsSuperview: TView; VAR itsParams: Ptr);
  82.                 OVERRIDE;
  83.                 PROCEDURE TReliefGridView.Fields (PROCEDURE DoToField (fieldName: Str255; fieldAddr: Ptr; fieldType: INTEGER));
  84.                 OVERRIDE;
  85.                 
  86.             { Drawing }
  87.                 PROCEDURE TReliefGridView.DrawCell (aCell: GridCell; aQDRect: Rect); OVERRIDE;
  88.                 PROCEDURE TReliefGridView.DrawSides (aCell: GridCell; aQDRect: Rect);
  89.                 PROCEDURE TReliefGridView.DrawSunkenSides (aCell: GridCell; aQDRect: Rect);
  90.                 PROCEDURE TReliefGridView.DrawRaisedSides (aCell: GridCell; aQDRect: Rect);
  91.  
  92.             { Setting and Getting instance variables }
  93.                 PROCEDURE TReliefGridView.SetLightColor (newColor: RGBColor);
  94.                 FUNCTION TReliefGridView.GetLightColor: RGBColor;
  95.                 PROCEDURE TReliefGridView.SetDarkColor (newColor: RGBColor);
  96.                 FUNCTION TReliefGridView.GetDarkColor: RGBColor;
  97.                 PROCEDURE TReliefGridView.GetSideColors;
  98.             END;
  99.  
  100. { •••••      Implementation        ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• }
  101. IMPLEMENTATION
  102.  
  103.     PROCEDURE TBkgndGridView.IRes (itsDocument: TDocument; itsSuperview: TView; VAR itsParams: Ptr);
  104.         OVERRIDE;
  105.     BEGIN
  106.         INHERITED IRes(itsDocument, itsSuperView, itsParams);
  107. { Set the background color defaults, then look for a resource }
  108.         SELF.fBkgndColor.red := 1000;
  109.         SELF.fBkgndColor.green := 30000;
  110.         SELF.fBkgndColor.blue := 1000;
  111.  
  112.         SELF.GetBkgndColor;
  113.     END;
  114.  
  115. {$S AFields}
  116.  
  117.     PROCEDURE TBkgndGridView.Fields (PROCEDURE DoToField (fieldName: Str255; fieldAddr: Ptr; fieldType: INTEGER));
  118.         OVERRIDE;
  119.  
  120.     BEGIN
  121.         DoToField('TGridView', NIL, bClass);
  122.         DoToField('fBkgndColor', @fBkgndColor, bRGBColor);
  123.  
  124.         INHERITED Fields(DoToField);
  125.     END;
  126.  
  127. {--------------------------------------------------------------------------------------------------}
  128. {$S ARes}
  129.     PROCEDURE TBkgndGridView.AdornCol (aCol: INTEGER; area: Rect);
  130.         OVERRIDE;
  131.     BEGIN
  132.         PenNormal;
  133.         PenSize(SELF.fColInset, SELF.fColInset);
  134.  
  135.         WITH area DO
  136.             BEGIN
  137.                 MoveTo(right - (SELF.fColInset DIV 2), top);
  138.                 LineTo(right - (SELF.fColInset DIV 2), bottom - SELF.fColInset);
  139.             END;
  140.  
  141.         IF aCol = 1 THEN        { for the first column }
  142.             WITH area DO
  143.                 BEGIN
  144.                     MoveTo(left, top);
  145.                     LineTo(left, bottom - 1);
  146.                 END;
  147.  
  148.     END;
  149.  
  150.  
  151.     PROCEDURE TBkgndGridView.AdornFirstColsLeft (area: Rect);
  152.     BEGIN
  153.         PenNormal;
  154.         PenSize(SELF.fColInset DIV 2, SELF.fColInset DIV 2);    { Only need half the line width, since there is no col }
  155.                                                 { inset for the preceeding col -- there is NO preceeding }
  156.                                                 { col .}
  157.         WITH area DO
  158.             BEGIN
  159.                 MoveTo(left, top);
  160.                 LineTo(left, bottom - 1);
  161.             END;
  162.  
  163.     END;
  164.  
  165.     PROCEDURE TBkgndGridView.AdornRow (aRow: INTEGER; area: Rect);
  166.         OVERRIDE;
  167.     BEGIN
  168.         PenNormal;
  169.         PenSize(SELF.fRowInset, SELF.fRowInset);
  170.  
  171.         WITH area DO
  172.             BEGIN
  173.                 MoveTo(left, bottom - (SELF.fRowInset DIV 2));
  174.                 LineTo(right - SELF.fRowInset, bottom - (SELF.fRowInset DIV 2));
  175.             END;
  176.  
  177.         IF aRow = 1 THEN        { for the first row }
  178.             SELF.AdornFirstRowsTop(area);
  179.     END;
  180.  
  181.     PROCEDURE TBkgndGridView.AdornFirstRowsTop (area: Rect);
  182.     BEGIN
  183.         PenNormal;
  184.         PenSize(SELF.fRowInset DIV 2, SELF.fRowInset DIV 2);    { Only need half the line width, since there is no row }
  185.                                                 { inset for the preceeding row -- there is NO preceeding }
  186.                                                 { row .}
  187.         WITH area DO
  188.             BEGIN
  189.                 MoveTo(left, top);
  190.                 LineTo(right, top);
  191.             END;
  192.  
  193.     END;
  194.  
  195.     PROCEDURE TBkgndGridView.DrawBkgnd (aCell: GridCell; aQDRect: Rect);
  196.         VAR
  197.             oldBkgndColor: RGBColor;
  198.             newBkgndColor: RGBColor;
  199.     BEGIN
  200.         GetIfColor(oldBkgndColor);
  201.  
  202.         newBkgndColor := SELF.fBkgndColor;
  203.         SetIfColor(newBkgndColor);
  204.         
  205.         FillRect(aQDRect, black);
  206.  
  207.         SetIfColor(oldBkgndColor);
  208.     END;
  209.  
  210.  
  211.     PROCEDURE TBkgndGridView.DrawCell (aCell: GridCell; aQDRect: Rect);
  212.     BEGIN
  213.         SELF.DrawBkgnd(aCell, aQDRect);
  214.     END;
  215.  
  216.  
  217.     PROCEDURE TBkgndGridView.GetBkgndColor;
  218.         VAR
  219.             initialBkgndColor: BkgndColorHdl;
  220.     BEGIN
  221.  
  222.         initialBkgndColor := NIL;
  223.         initialBkgndColor := BkgndColorHdl(Get1Resource(kBkgndColorRsrcType, 800));
  224.         FailNIL(initialBkgndColor);
  225.         FailResError;
  226.  
  227.         WITH initialBkgndColor^^ DO
  228.             BEGIN
  229.                 SELF.fBkgndColor.red := redPart;
  230.                 SELF.fBkgndColor.green := greenPart;
  231.                 SELF.fBkgndColor.blue := bluePart;
  232.             END;
  233.     END;
  234.  
  235.  
  236.     FUNCTION TBkgndGridView.GetColor: RGBColor;
  237.     BEGIN
  238.         GetColor := SELF.fBkgndColor;
  239.     END;
  240.  
  241.  
  242.     PROCEDURE TBkgndGridView.SetColor (newColor: RGBColor);
  243.     BEGIN
  244.         SELF.fBkgndColor := newColor;
  245.     END;
  246.  
  247.  
  248.  
  249. { ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• }
  250.  
  251. PROCEDURE TReliefGridView.IRes (itsDocument: TDocument; itsSuperview: TView; VAR itsParams: Ptr);
  252.     OVERRIDE;
  253. BEGIN
  254.     INHERITED IRes(itsDocument, itsSuperView, itsParams);
  255.     
  256.   { Set the side colors defaults, then look for a resource }
  257.     SELF.fLightestSideColor.red := 26000;
  258.     SELF.fLightestSideColor.green := 31000;
  259.     SELF.fLightestSideColor.blue := 0;
  260.  
  261.     SELF.fLightSideColor.red := 26000;
  262.     SELF.fLightSideColor.green := 31000;
  263.     SELF.fLightSideColor.blue := 0;
  264.  
  265.     SELF.fDarkSideColor.red := 500;
  266.     SELF.fDarkSideColor.green := 15000;
  267.     SELF.fDarkSideColor.blue := 500;
  268.  
  269.     SELF.fDarkestSideColor.red := 500;
  270.     SELF.fDarkestSideColor.green := 15000;
  271.     SELF.fDarkestSideColor.blue := 500;
  272.  
  273.     SELF.fSideWidth := 3;
  274.  
  275.     SELF.GetSideColors;
  276. END;
  277.  
  278. {--------------------------------------------------------------------------------------------------}
  279. {$S AFields}
  280. PROCEDURE TReliefGridView.Fields (PROCEDURE DoToField (fieldName: Str255; fieldAddr: Ptr; fieldType: INTEGER));
  281.     OVERRIDE;
  282.  
  283. BEGIN
  284.     DoToField('TGridView', NIL, bClass);
  285.     DoToField('fLightestSideColor', @fLightestSideColor, bRGBColor);
  286.     DoToField('fLightSideColor', @fLightSideColor, bRGBColor);
  287.     DoToField('fDarkSideColor', @fDarkSideColor, bRGBColor);
  288.     DoToField('fDarkestSideColor', @fDarkestSideColor, bRGBColor);
  289.     DoToField('fSideWidth', @fSideWidth, bInteger);
  290.  
  291.     INHERITED Fields(DoToField);
  292. END;
  293.  
  294. {--------------------------------------------------------------------------------------------------}
  295. {$S ARes}
  296. PROCEDURE TReliefGridView.DrawCell (aCell: GridCell; aQDRect: Rect);
  297. BEGIN
  298.     INHERITED DrawCell(aCell, aQDRect);
  299.  
  300.     SELF.DrawSides(aCell, aQDRect);
  301. END;
  302.  
  303. {--------------------------------------------------------------------------------------------------}
  304. {$S ARes}
  305. PROCEDURE TReliefGridView.DrawSides (aCell: GridCell; aQDRect: Rect);
  306. VAR
  307.     oldColor: RGBColor;
  308.     newColor: RGBColor;
  309.     i: INTEGER;    { DO Loop index }
  310.     
  311. BEGIN
  312.     GetIfColor(oldColor);
  313.  
  314.     WITH aQDRect DO
  315.         BEGIN
  316.             newColor := SELF.fLightestSideColor;
  317.             SetIfColor(newColor);
  318.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  319.                 BEGIN
  320.                     MoveTo(left + i, top + i);            { Left Side line - Lightest side color }
  321.                     LineTo(left + i, bottom - 1);
  322.                 END;
  323.  
  324.             newColor := SELF.fLightSideColor;
  325.             SetIfColor(newColor);
  326.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  327.                 BEGIN
  328.                     MoveTo(left + i, top + i);            { Top line  - Light side color }
  329.                     LineTo(right - 1, top + i);
  330.                 END;
  331.  
  332.             newColor := SELF.fDarkSideColor;
  333.             SetIfColor(newColor);
  334.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  335.                 BEGIN
  336.                     MoveTo(left + i, bottom - 1 - i);    { Bottom line - Dark side color }
  337.                     LineTo(right - 1, bottom - 1 - i);
  338.                 END;
  339.  
  340.             newColor := SELF.fDarkestSideColor;
  341.             SetIfColor(newColor);
  342.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  343.                 BEGIN
  344.                     MoveTo(right - 1 - i, top + 1 + i);    { Right side line - Darkest side color }
  345.                     LineTo(right - 1 - i, bottom - 1 - i);
  346.                 END;
  347.         END;
  348.  
  349.     SetIfColor(oldColor);
  350. END;
  351.  
  352. {--------------------------------------------------------------------------------------------------}
  353. {$S ARes}
  354. PROCEDURE TReliefGridView.DrawRaisedSides (aCell: GridCell; aQDRect: Rect);
  355. VAR
  356.     oldColor: RGBColor;
  357.     newColor: RGBColor;
  358.     i: INTEGER;    { DO Loop index }
  359.     
  360. BEGIN
  361.     GetIfColor(oldColor);
  362.  
  363.     WITH aQDRect DO
  364.         BEGIN
  365.             newColor := SELF.fLightestSideColor;
  366.             SetIfColor(newColor);
  367.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  368.                 BEGIN
  369.                     MoveTo(left + i, top + i);            { Left Side line - now, the darkest side color }
  370.                     LineTo(left + i, bottom - 2);
  371.                 END;
  372.  
  373.             newColor := SELF.fLightSideColor;
  374.             SetIfColor(newColor);
  375.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  376.                 BEGIN
  377.                     MoveTo(left + i, top + i);            { Top line  - now, the dark side color }
  378.                     LineTo(right - 2, top + i);
  379.                 END;
  380.  
  381.             newColor := SELF.fDarkSideColor;
  382.             SetIfColor(newColor);
  383.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  384.                 BEGIN
  385.                     MoveTo(left + i, bottom - 2 - i);    { Bottom line - Dark side color }
  386.                     LineTo(right - 2, bottom - 2 - i);
  387.                 END;
  388.  
  389.             newColor := SELF.fDarkestSideColor;
  390.             SetIfColor(newColor);
  391.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  392.                 BEGIN
  393.                     MoveTo(right - 2 - i, top + 1 + i);    { Right side line - Darkest side color }
  394.                     LineTo(right - 2 - i, bottom - 2 - i);
  395.                 END;
  396.         END;
  397.  
  398.     SetIfColor(oldColor);
  399. END;
  400.  
  401. {--------------------------------------------------------------------------------------------------}
  402. {$S ARes}
  403. PROCEDURE TReliefGridView.DrawSunkenSides (aCell: GridCell; aQDRect: Rect);
  404. VAR
  405.     oldColor: RGBColor;
  406.     newColor: RGBColor;
  407.     i: INTEGER;    { DO Loop index }
  408.  
  409. BEGIN
  410.     GetIfColor(oldColor);
  411.  
  412.     WITH aQDRect DO
  413.         BEGIN
  414.             newColor := SELF.fDarkestSideColor;
  415.             SetIfColor(newColor);
  416.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  417.                 BEGIN
  418.                     MoveTo(left + i, top + i);            { Left Side line - now, the darkest side color }
  419.                     LineTo(left + i, bottom - 2);
  420.                 END;
  421.  
  422.             newColor := SELF.fDarkSideColor;
  423.             SetIfColor(newColor);
  424.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  425.                 BEGIN
  426.                     MoveTo(left + i, top + i);            { Top line  - now, the dark side color }
  427.                     LineTo(right - 2, top + i);
  428.                 END;
  429.  
  430.             newColor := SELF.fLightSideColor;
  431.             SetIfColor(newColor);
  432.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  433.                 BEGIN
  434.                     MoveTo(left + i, bottom - 2 - i);    { Bottom line - Dark side color }
  435.                     LineTo(right - 2, bottom - 2 - i);
  436.                 END;
  437.  
  438.             newColor := SELF.fLightestSideColor;
  439.             SetIfColor(newColor);
  440.             FOR i := 0 TO (SELF.fSideWidth - 1) DO
  441.                 BEGIN
  442.                     MoveTo(right - 2 - i, top + 1 + i);    { Right side line - Darkest side color }
  443.                     LineTo(right - 2 - i, bottom - 2 - i);
  444.                 END;
  445.         END;
  446.  
  447.     SetIfColor(oldColor);
  448. END;
  449.  
  450.  
  451.  
  452. {--------------------------------------------------------------------------------------------------}
  453. {$S ARes}
  454. PROCEDURE TReliefGridView.GetSideColors;
  455.     VAR
  456.         initialSideColors: SideColorsHdl;
  457. BEGIN
  458.  
  459.     initialSideColors := NIL;
  460.     initialSideColors := SideColorsHdl(Get1Resource(kSideColorRsrcType, 800));
  461.     FailNIL(initialSideColors);
  462.     FailResError;
  463.  
  464.     WITH initialSideColors^^ DO
  465.         BEGIN
  466.             SELF.fLightestSideColor.red := redPartLightestSide;
  467.             SELF.fLightestSideColor.green := greenPartLightestSide;
  468.             SELF.fLightestSideColor.blue := bluePartLightestSide;
  469.  
  470.             SELF.fLightSideColor.red := redPartLightSide;
  471.             SELF.fLightSideColor.green := greenPartLightSide;
  472.             SELF.fLightSideColor.blue := bluePartLightSide;
  473.  
  474.             SELF.fDarkSideColor.red := redPartDarkSide;
  475.             SELF.fDarkSideColor.green := greenPartDarkSide;
  476.             SELF.fDarkSideColor.blue := bluePartDarkSide;
  477.  
  478.             SELF.fDarkestSideColor.red := redPartDarkestSide;
  479.             SELF.fDarkestSideColor.green := greenPartDarkestSide;
  480.             SELF.fDarkestSideColor.blue := bluePartDarkestSide;
  481.         END;
  482. END;
  483.  
  484.  
  485.  
  486. {--------------------------------------------------------------------------------------------------}
  487. {$S ARes}
  488. PROCEDURE TReliefGridView.SetLightColor (newColor: RGBColor);
  489. BEGIN
  490. END;
  491.  
  492.  
  493. {--------------------------------------------------------------------------------------------------}
  494. {$S ARes}
  495. FUNCTION TReliefGridView.GetLightColor: RGBColor;
  496. BEGIN
  497. END;
  498.  
  499.  
  500. {--------------------------------------------------------------------------------------------------}
  501. {$S ARes}
  502. PROCEDURE TReliefGridView.SetDarkColor (newColor: RGBColor);
  503. BEGIN
  504. END;
  505.  
  506.  
  507. {--------------------------------------------------------------------------------------------------}
  508. {$S ARes}
  509. FUNCTION TReliefGridView.GetDarkColor: RGBColor;
  510. BEGIN
  511. END;
  512.  
  513.  
  514.  
  515. END.